<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>简单计算器</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f0f0;
        }
        .calculator {
            padding: 20px;
            background: white;
            border: 1px solid #ccc;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        .display {
            width: 210px;
            height: 30px;
            margin-bottom: 10px;
            text-align: right;
            padding: 5px;
            border: 1px solid #ccc;
        }
        .buttons {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 10px;
        }
        button {
            padding: 10px;
            font-size: 16px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="calculator">
        <div class="display" id="display"></div>
        <div class="buttons">
            <button onclick="input('1')">1</button>
            <button onclick="input('2')">2</button>
            <button onclick="input('3')">3</button>
            <button onclick="operation('+')">+</button>
            <button onclick="input('4')">4</button>
            <button onclick="input('5')">5</button>
            <button onclick="input('6')">6</button>
            <button onclick="operation('-')">-</button>
            <button onclick="input('7')">7</button>
            <button onclick="input('8')">8</button>
            <button onclick="input('9')">9</button>
            <button onclick="operation('*')">*</button>
            <button onclick="input('0')">0</button>
            <button onclick="clearDisplay()">C</button>
            <button onclick="calculate()">=</button>
            <button onclick="operation('/')">/</button>
        </div>
    </div>

    <script>
        let display = document.getElementById('display');
        let currentInput = '';
        let previousInput = '';
        let operation = null;

        function input(number) {
            currentInput += number;
            display.innerText = currentInput;
        }

        function operation(op) {
            previousInput = currentInput;
            operation = op;
            currentInput = '';
            display.innerText = '';
        }

        function calculate() {
            if (operation && previousInput && currentInput) {
                let result = 0;
                switch (operation) {
                    case '+':
                        result = parseFloat(previousInput) + parseFloat(currentInput);
                        break;
                    case '-':
                        result = parseFloat(previousInput) - parseFloat(currentInput);
                        break;
                    case '*':
                        result = parseFloat(previousInput) * parseFloat(currentInput);
                        break;
                    case '/':
                        result = parseFloat(previousInput) / parseFloat(currentInput);
                        break;
                }
                display.innerText = result;
                currentInput = result.toString();
                previousInput = '';
                operation = null;
            }
        }

        function clearDisplay() {
            currentInput = '';
            previousInput = '';
            operation = null;
            display.innerText = '';
        }
    </script>
</body>
</html>